<?php

declare(strict_types=1);

namespace owns\auth;

use app\model\system\UserModel;
use owns\enum\SysEnum;

/**
 * 管理员
 */
class UserAuth
{
    private static $obj;

    private object $auth;

    private function __construct()
    {
        $this->auth = request()->auth;
    }
    public function __clone()
    {
    }
    /**
     * 实例化
     */
    public static function instance(): UserAuth
    {
        if (self::$obj instanceof UserAuth) {
            return self::$obj;
        }
        self::$obj = new self();
        return self::$obj;
    }
    /**
     * 开发者
     */
    public function root(): bool
    {
        return SysEnum::isRoot($this->auth->uid);
    }
    /**
     * 超管
     */
    public function super(): bool
    {
        return $this->auth->super;
    }
    /**
     * 账户信息
     */
    public function info(): object
    {
        return $this->auth;
    }
    /** 
     * 管理员id
     */
    public function uid(): int
    {
        return $this->auth->uid;
    }
    /**
     * 账号
     */
    public function username()
    {
        return $this->auth->username;
    }
    
    /**
     * 所属分组
     */
    public function group(): bool
    {
        return $this->auth->group_id;
    }
    /**
     * 管理员角色id
     */
    public function role(): int
    {
        return $this->auth->role_id;
    }
}
